<include file="Public:head" title='管理员详情' />
<script src="__PUBLIC__/js/Jquery/validate.js"></script>
<script type="text/javascript">
    $(function() {
        var id = '{$detail.id}';
        var is_true = true;
        if (id > 0) {
            is_true = false;
        }
        var id_url = '';
        if (id > 0) {
            id_url = "/id/" + id + ".html";
        }
        var actions = "{$detail.action}";
        if(actions){
            actions = actions.split(",");
            for(var i=0;i<actions.length;i++){
                $("input[value="+actions[i]+"]").prop("checked","checked");
            }
           
        }
        $("#form").validate({
            errorPlacement: function(error, element) {
                var error_td = element.parent('td');
                error_td.find('label.error').hide();
                error_td.append(error);
            },
            submitHandler: function(form) {
                var len =   $("#form").find("input[type=checkbox]:checked").length;
     if(len == 0){
         alert("至少选择一项权限！");
         return false;
     }else{
           form.submit();
     }
              
            },
            rules: {
                name: {
                    required: true,
                    remote: {
                        url: '__APP__/{$Think.MODULE_NAME}/Ajax/check_admin_name' + id_url,
                        type: 'post',
                        data: {
                            name: function() {
                                return $('#name').val();
                            }
                        }
                    }
                },
                pwd: {
                    required: is_true,
                    minlength: 5
                },
                pwd2: {
                    required: is_true,
                    equalTo: '#pwd'
                }

            },
            messages: {
                name: {
                    required: '用户名不能为空',
                    remote: '该用户名已经存在'
                },
                pwd: {
                    required: '密码不能为空',
                    minlength: '密码长度应在5-20个字符之间'
                },
                pwd2: {
                    required: '请再次输入您的密码',
                    equalTo: '两次输入的密码不一致'
                }

            }
        });
    });
    function first(obj){
        var checked = obj.prop("checked");
        var id = obj.val();
        if(checked == true){
            $("#td_"+id).find("input[type=checkbox]").prop("checked","checked")
        }else{
            $("#td_"+id).find("input[type=checkbox]").removeAttr("checked")
        }
    }
    function second(obj){
        var checked = obj.prop("checked");
        var id = obj.val();
        var id =  "first_"+obj.parents("td.td").attr("data-id");
        if($("."+id+":checked").length == $("."+id).length){
            $("#"+id).prop("checked","checked");
        }else{
            $("#"+id).removeAttr("checked")
        }
    }
</script>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <include file="Public:left" />
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="__APP__/{$Think.MODULE_NAME}">首页</a></li>
                    <li><a href="{:U('Index/managers')}">管理员管理</a></li>
                    <li class="active">管理员详情</li>
                </ul>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-12">
                                <h3 class="header smaller lighter blue">菜单{$Think.get.id|getPageType}</h3>

                                <form action="{:U('Index/managers_detail_post')}" method="POST" id="form"  enctype="multipart/form-data" >
                                    <table class="table table_detail">
                                        <tbody>
                                            <tr>
                                                <td class="td_left">用户名:</td>
                                                <td>
                                                    <input class="common_txt" type="text" value="{$detail.name}" name="name" id="name"  maxlength="20" autocomplete="off"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td  class="td_left">密码:</td>
                                                <td>
                                                    <input class="common_txt" type="password" value="" name="pwd" id="pwd" maxlength="20"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td  class="td_left">确认密码:</td>
                                                <td>
                                                    <input class="common_txt" type="password" value="" name="pwd2" id="pwd2"maxlength="20"  />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td   class="td_left">权限:</td>
                                                <td>
                                                    <table style="width:100%">
                                                        <foreach name="menus" item="row">
                                                            <tr>
                                                                <td width="120px">
                                                                    <label style="width:120px;display: inline-block"> 
                                                                        <input  type="checkbox" value="{$row.id}" name="power[]" id="first_{$row.id}" class="first" autocomplete="off"  onclick="first($(this))"
                                                                                {$detail.power|getChecked=###,$row['id']}/> 
                                                                                <span style="font-weight: bold">{$row.name}</span>
                                                                    </label>
                                                                </td>
                                                                <td id="td_{$row.id}" class="td" data-id="{$row.id}">
                                                            <foreach name="row['sub']" item="row2">
                                                                <label style="width:120px;display: inline-block"> 
                                                                    <input  type="checkbox" value="{$row2.id}" name="power[]" autocomplete="off"  class="second second_{$row2.id} first_{$row.id}"
                                                                            onclick="second($(this))"       {$detail.power|getChecked=###,$row2['id']}  /> 
                                                                            <span style="color:green"> {$row2.name}</span>
                                                                </label>
                                                            </foreach>
                                                            </td>
                                                            </tr>
                                                        </foreach>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_left"></td>
                                                <td>
                                                    <input type='hidden' name='id' value='{$Think.get.id}'/>
                                                    <button class="btn btn-info btn-sm" type="submit">
                                                        <i class="icon-ok bigger-110 "></i>
                                                        保 存
                                                    </button>
                                                    <button class="btn btn-sm reset" type="button" onclick="goUrl(-1)">
                                                        <i class="icon-undo bigger-110"></i>
                                                        返 回
                                                    </button>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <include file="Public:setting" />
    </div>
</div>
<include file="Public:foot" />